package com.passer.toolbox.minecraft.translation;

import com.alibaba.fastjson2.JSONObject;
import com.passer.toolbox.common.file.util.ReadFileUtils;
import com.passer.toolbox.common.core.util.StringUtils;
import com.passer.toolbox.common.file.util.WriteFileUtils;

import java.io.IOException;

public class TranslateMod {
    public void updateTranslation(String oldFile, String newFile, String saveFile) {
        JSONObject oldJson;
        JSONObject newJson;
        try {
            oldJson = ReadFileUtils.readJsonFile(oldFile);
            newJson = ReadFileUtils.readJsonFile(newFile);
        } catch (IOException e) {
            System.out.println("文件读取失败：" + e.getMessage());
            return;
        }
        newJson.forEach((key, value) -> {
            String oldJsonString = oldJson.getString(key);
            if (StringUtils.isNotEmpty(oldJsonString)) {
                newJson.replace(key, oldJsonString);
            }
        });
        try {
            WriteFileUtils.writeFileByString(saveFile, newJson.toString());
        } catch (IOException e) {
            System.out.println("文件写入失败：" + e.getMessage());
        }
    }
}
